package com.legendshop.openportal.sdk.model.request.v4;

import cn.hutool.core.util.StrUtil;
import com.legendshop.openportal.sdk.annotation.DateValid;
import com.legendshop.openportal.sdk.model.PageRequest;
import com.legendshop.openportal.sdk.model.constants.DateQueryTypeEnum;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.validation.constraints.AssertTrue;
import javax.validation.constraints.NotNull;

import static com.legendshop.openportal.sdk.model.constants.ApiPathConstantsV4.USER_PAGE_V4;

/**
 * @author jzh
 * @version 1.0.0
 * @title UserPageV4Request
 * @date 2025/5/14 13:53
 * @description：用户分页V4请求参数
 */
@Data
public class UserPageV4Request extends PageRequest {

    private static final long serialVersionUID = -1420435436489834264L;

    /**
     * 店铺id
     */
    @NotNull(message = "店铺id不能为空")
    @ApiModelProperty("店铺id")
    private Long shopId;

    @DateValid(message = "开始时间格式不正确", ignoreEmpty = true)
    @ApiModelProperty(value = "开始时间，需与结束时间同时传")
    private String startDate;

    @DateValid(message = "结束时间格式不正确", ignoreEmpty = true)
    @ApiModelProperty(value = "结束时间，需与开始时间同时传")
    private String endDate;

    @ApiModelProperty(value = "时间查询类型，默认为更新时间")
    private DateQueryTypeEnum dateQueryType;

    @Override
    public String getApiPath() {
        return USER_PAGE_V4;
    }

    @AssertTrue(message = "开始时间必须小于等于结束时间")
    public boolean getStartDateBeforeEndDate() {
        if (StrUtil.isBlank(startDate)) {
            return StrUtil.isBlank(endDate);
        }
        if (StrUtil.isBlank(endDate)) {
            return false;
        }
        return startDate.compareTo(endDate) <= 0;
    }
}
